<template>
	<view class="content">
		<view class="search-box">
			<view class="search-box">
				<view class="search-left-box">
					<uni-search-bar @confirm="search" v-model="searchValue" @cancel="cancel" @clear="clear"
						placeholder="输入抽检批次号">
					</uni-search-bar>
				</view>
				<view class="search-right-box">
					<uni-search-bar @confirm="search1" v-model="searchValue1" @cancel="cancel1" @clear="clear1"
						placeholder="输入样品编号">
					</uni-search-bar>
				</view>
			</view>
		</view>
		<view class="table-box">
			<view :class="tableIndex==index?'tableChange':'table'" v-for="(item,index) in tableList" :key="index"
				@click="tableChange(item,index)">
				<text>{{item.title}}</text>
				<view class="border">
				</view>
			</view>
		</view>
		<z-paging ref="paging" v-model="dataList" :default-page-size="row" @onRefresh="onRefresh" @query="getList"
			auto-show-system-loading auto-show-back-to-top>
			<view class="" style="padding: 190rpx 20rpx 180rpx 20rpx;">
				<view class="list-box" v-for="(item,index) in dataList" :key="index">
					<view class="top-box">
						<view class="status-box">
							<view class="item-box" v-if="tableIndex == 0">
								外观检测
							</view>
							<view class="item-box" v-if="tableIndex == 1">
								尺寸检测
							</view>
						</view>
					</view>
					<view class="xian"></view>
					<view class="title-box" v-if="item.goodsName">
						产品：{{item.goodsName}}
					</view>
					<view class="title-box" v-if="item.batchNumber">
						抽检批次号：{{item.batchNumber}}
					</view>
					<view class="title-box" v-if="item.sampleNumber">
						样品编号：{{item.sampleNumber}}
					</view>
					<view class="info-box">
						<view class="info-item">
							<view class="info-item-title">
								检验时间
							</view>
							<view class="info-item-text">
								{{item.inspectTime}}
							</view>
						</view>
						<view class="info-item">
							<view class="info-item-title">
								是否合格
							</view>
							<view class="info-item-text">
								{{$tools.dictDispose(yes_no,item.testPass)}}
							</view>
						</view>
						<view class="info-item" v-if="tableIndex == 0">
							<view class="info-item-title">
								外观
							</view>
							<view class="info-item-text">
								{{item.surfaceQuality || ''}}
							</view>
						</view>
						<view class="info-item" v-if="tableIndex == 1">
							<view class="info-item-title">
								尺寸
							</view>
							<view class="info-item-text">
								{{item.size || ''}}
							</view>
						</view>
						<view class="info-item">
							<view class="info-item-title">
								质检报告
							</view>
							<view class="info-item-text" style="color: blue;"  @click.stop="pdfBnt(item.reportFile)">
								<!-- {{item.reportFile}} -->
								点击查看报告详情
							</view>
						</view>
					</view>
					<view class="text-box" v-if="item.remark">
						备注：{{item.remark}}
					</view>
					<view class="xian"></view>
					<view class="bnt-box">
						<view class="bnt-big-box">
							<view class="bnt" @click.stop="detilBnt(item)">
								详情
							</view>
							<view class="bnt1" @click.stop="editBnt(item)">
								修改
							</view>
							<view class="bnt1" @click.stop="deleteBnt(item)">
								删除
							</view>
						</view>
					</view>
				</view>
			</view>
		</z-paging>
		<view class="bomBox" v-if="tableIndex == 0">
			<view class="textbnt" @click.stop="addBnt(0)">
				新增外观检查
			</view>
		</view>
		<view class="bomBox" v-if="tableIndex == 1">
			<view class="textbnt" @click.stop="addBnt(1)">
				新增尺寸检查
			</view>
		</view>
	</view>
</template>

<script>
	import * as index from '@/api/index.js'
	// import config from '@/config'
	// import {
	// 	goodsSaledoGongxuUserList,
	// 	removeUpdate
	// } from "@/api/system/index"
	export default {
		data() {
			return {
				baseUrl: this.$tools.baseURL,
				id: "",
				name: '',
				text: '',
				searchValue: '',
				searchValue1: '',
				tableList: [{
						title: '外观检测',
						status: 1,
						state: 1,
					},
					{
						title: '尺寸检测',
						status: 2,
						state: 2
					}
				], //table列表
				row: 10,
				tabList: [],
				tableIndex: 0, //当前选择
				dataList: [],
				status: '',
				yes_no: []
			}
		},
		onLoad(e) {
			this.id = e.id
			this.dictType() // 数据字典查询
		},
		methods: {
			reload() {
				console.log('重新加载');
				this.$nextTick(() => {
					this.$refs.paging.reload()
				})
			},
			pdfBnt(e) {
				let that = this
				uni.setStorage({
					key: 'link',
					data: that.baseUrl + e,
					success: function() {
						uni.navigateTo({
							url: '/pages/webView/index'
						})
					}
				});
			},
			dictType() {
				index.typesBatch({
					'yes_no': 'yes_no',
				}).then(res => {
					this.yes_no = res.data.yes_no
				})
			},
			reload() {
				console.log('重新加载');
				this.$nextTick(() => {
					this.$refs.paging.reload()
				})
			},
			detilBnt(e) {
				uni.navigateTo({
					url: '/pagesA/orderAdmin/qualityTesting/pollingList/pollingDeitil/index?id=' + e.id + '&type='  + this.tableIndex
				});
			},
			addBnt(e) {
				uni.navigateTo({
					url: '/pagesA/orderAdmin/qualityTesting/pollingList/pollingAddForm/index?type=' + e + '&reportWorkId=' + this.id
				});
				
			},
			editBnt(e) {
				uni.navigateTo({
					url: '/pagesA/orderAdmin/qualityTesting/pollingList/pollingAddForm/index?id=' + e.id + '&type='  + this.tableIndex
				});
			},
			deleteBnt(e) {
				if (this.tableIndex == 0) {
					var add = e
					uni.showModal({
						title: '提示',
						content: '确定删除记录吗？',
						success: (res) => {
							if (res.confirm) {
								index.factoryTestSurfaceDele({id:add.id}).then(res => {
									this.$refs.paging.reload()
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else {
					var add = e
					uni.showModal({
						title: '提示',
						content: '确定删除记录吗？',
						success: (res) => {
							if (res.confirm) {
								index.factoryTestSizeDele({id:add.id}).then(res => {
									this.$refs.paging.reload()
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
				
			},
			// 当页面滚动到底部事件被触发
			onReachBottom() {
				// 通知z-paging滚动到底部了，z-paging会进行相应的处理，例如加载更多数据
				this.$refs.paging.pageReachBottom();
			},
			// 下拉刷新被触发
			onRefresh() {
				// 告知z-paging下拉刷新结束，这样才可以开始下一次的下拉刷新
				setTimeout(() => {
					this.$tools.toast('刷新成功～')
				}, 500)
			},
			// @query所绑定的方法不要自己调用！！需要刷新列表数据时，只需要调用this.$refs.paging.reload()即可
			getList(pageNum, pageSize) {
				if(this.tableIndex == 0) {
					index.factoryTestSurfaceList({
						pageNum,
						pageSize,
						reportWorkId: this.id,
						// batchNumber: this.searchValue,
						// sampleNumber: this.searchValue1,
						orderByColumn: "create_time",
						isAsc: "desc"
					}).then(res => {
						this.$refs.paging.complete(res.rows);
						console.log(res, '这是什么')
					})
				} else {
					index.factoryTestSizeList({
						pageNum,
						pageSize,
						reportWorkId: this.id,
						// batchNumber: this.searchValue,
						// sampleNumber: this.searchValue1,
						orderByColumn: "create_time",
						isAsc: "desc"
					}).then(res => {
						this.$refs.paging.complete(res.rows);
						console.log(res, '这是什么')
					})
				}
			},
			inputDialogToggle(e) {
				this.text = e
				this.$refs.inputDialog.open()
			},
			tableChange(item, index) {
				this.tableIndex = index
				this.status = item.status
				this.$refs.paging.reload()
			},
			goto() {
				uni.navigateTo({
					url: '/pagesA/remit/details/index'
				})
			},
			goto2() {
				uni.navigateTo({
					url: '/pagesA/remit/commodity/index'
				})
			},
			search(res) {
				this.$refs.paging.reload()
			},
			clear(res) {
				this.searchValue = ''
				this.$refs.paging.reload()
			},
			cancel(res) {
				this.searchValue = ''
				this.$refs.paging.reload()
			},
			search1(res) {
				this.$refs.paging.reload()
			},
			clear1(res) {
				this.searchValue1 = ''
				this.$refs.paging.reload()
			},
			cancel1(res) {
				this.searchValue1 = ''
				this.$refs.paging.reload()
			},

		}

	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding-left: 20rpx;
		padding-right: 20rpx;

		.search-box {
			width: 750rpx;
			height: 103rpx;
			background: #FFFFFF;
			z-index: 99;
			display: flex;
			align-items: center;

			.search-left-box {
				width: 50%;
			}

			.search-right-box {
				width: 45%;
			}
		}

		.table-box {
			width: 750rpx;
			position: sticky;
			top: 0;
			z-index: 2;
			background: #ffffff;
			display: flex;
			justify-content: space-around;

			.table {
				padding: 23rpx 0;
				font-size: 28rpx;
				font-weight: 400;
				color: #666666;
				display: flex;
				flex-direction: column;
				align-items: center;

				.border {
					margin-top: 10rpx;
					width: 32rpx;
					height: 4rpx;
				}
			}

			.tableChange {
				padding: 23rpx 0;
				font-size: 28rpx;
				font-weight: 400;
				color: #333333;
				display: flex;
				flex-direction: column;
				align-items: center;

				.border {
					margin-top: 10rpx;
					width: 32rpx;
					height: 4rpx;
					background: #8295BC;
				}
			}
		}

		.search-box {
			width: 750rpx;
			height: 103rpx;
			background: #FFFFFF;
			z-index: 99;
		}

		.list-box {
			padding-right: 20rpx;
			padding-left: 20rpx;
			margin-top: 20rpx;
			border-radius: 8rpx;
			background: #FFF;

			.top-box {
				display: flex;
				align-items: center;
				padding: 20rpx 0rpx;

				.tiem-box {
					color: #999;
					font-size: 24rpx;
				}

				.status-box {
					margin-left: auto;
					display: flex;
					align-items: center;

					.item-box {
						padding: 4rpx 12rpx;
						height: 42rpx;
						border-radius: 10rpx;
						background: #F5F7FB;
						color: #8295BC;
						font-size: 24rpx;
					}
				}
			}

			.xian {
				width: 662rpx;
				border-bottom: 1px solid #EAEAEA;
			}

			.title-box {
				width: 670rpx;
				padding-top: 10rpx;
				padding-bottom: 10rpx;
				color: #333;
				font-size: 28rpx;
				font-weight: bold;
				word-wrap: break-word;
			}

			.info-box {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;
				border-radius: 8rpx;
				background: #F5F7FB;
				padding-top: 10rpx;
				padding-bottom: 10rpx;

				.info-item {
					flex: 0 0 calc(45% - 20rpx);
					margin-top: 20rpx;
					margin-bottom: 30rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					// justify-content: center;

					.info-item-title {
						font-weight: bold;
						margin-bottom: 10rpx;
						color: #999;
						font-size: 24rpx;
					}

					.info-item-text {
						margin-top: 8rpx;
						color: #333;
						font-size: 28rpx;
						font-weight: bold;
					}
				}
			}

			.text-box {
				padding-top: 20rpx;
				padding-bottom: 20rpx;
				color: #999;
				font-size: 24rpx;
			}

			.bnt-box {
				padding-top: 20rpx;
				padding-bottom: 20rpx;

				.bnt-big-box {
					display: flex;
					justify-content: flex-end;
					align-items: center;

					.bnt {
						margin-right: 20rpx;
						display: flex;
						align-items: center;
						border-radius: 10rpx;
						background: #F5F7FB;
						padding: 15rpx 30rpx 15rpx 30rpx;
						color: #4D8987;
						font-size: 24rpx;
					}

					.bnt1 {
						margin-right: 20rpx;
						display: flex;
						align-items: center;
						border-radius: 10rpx;
						background: #4D8987;
						padding: 15rpx 30rpx 15rpx 30rpx;
						color: #ffffff;
						font-size: 24rpx;
					}
				}
			}
		}
		.bomBox {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 750rpx;
			background-color: #FFFFFF;
			height: 150rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			.textbnt {
				color: #fff;
				width: 690rpx;
				height: 88rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 10rpx;
				background-color: #4D8987;
			}
		}
	}
</style>